package controllers;

import entity.User;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.stage.Modality;
import javafx.stage.Stage;
import view.EditingInformationInterface;

/**
 * @author zjw
 * @date 2020/1/8 11:14
 */
public class PersonalInformationControllers {
    private User user;
    private Stage primaryStage;
    private Button editorButton;

    public PersonalInformationControllers(User user, Stage primaryStage) {
        this.user = user;
        this.primaryStage = primaryStage;
        this.editorButton = new Button("编辑");
    }

    public Button getEditorButton() {
        editorButton.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent event) {
                try {
                    Stage newStage = new Stage();
                    newStage.setResizable(false);
                    newStage.initModality(Modality.APPLICATION_MODAL);  // 将新界面设置成模态，则界面编程不可编辑状态
                    EditingInformationInterface editingInformation = new EditingInformationInterface(user, newStage);
                    editingInformation.start();
                    primaryStage.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
        return editorButton;
    }
}
